package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.FindRoot;

import java.util.ArrayList;

import de.hdodenhof.circleimageview.CircleImageView;
import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/24.
 */
public class FindGridviewAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<FindRoot.DatasEntity.DataEntity> entityArrayList;

    public FindGridviewAdapter(Context context, ArrayList<FindRoot.DatasEntity.DataEntity> entityArrayList) {
        this.context = context;
        this.entityArrayList = entityArrayList;
    }

    @Override
    public int getCount() {
        return entityArrayList == null ? 0 : entityArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return entityArrayList == null ? null : entityArrayList.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.gridview_item, null);
            holder = new ViewHolder();
            holder.find_hot_songs_img = (ImageView) convertView.findViewById(R.id.find_hot_songs_img);
            holder.find_hot_songs_name = (TextView) convertView.findViewById(R.id.find_hot_songs_name);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
            holder.find_hot_songs_name.setText(entityArrayList.get(position % entityArrayList.size()).getName());
            Picasso.with(context).load(entityArrayList.get(position % entityArrayList.size()).getPicUrl()).into(holder.find_hot_songs_img);

        return convertView;
    }
   public class ViewHolder {
       private ImageView find_hot_songs_img;
       private TextView find_hot_songs_name;
   }
}
